Skip to content

Recipient unsent messages#73

Merged
kentcdodds merged 11 commits into
mainfrom
cursor/recipient-unsent-messages-800d
Feb 2, 2026
Merged

Recipient unsent messages#73
kentcdodds merged 11 commits into
mainfrom
cursor/recipient-unsent-messages-800d

Conversation

@kentcdodds
Copy link
Copy Markdown
Member

@kentcdodds kentcdodds commented Feb 2, 2026

Summary

Replaced a single, slow query for paginated recipients with unsent message counts with a split-query approach. This eliminates global aggregates and planner-hostile SQL by fetching recipients first, then querying unsent message counts for only those recipients, and merging results in application code. New composite recipient_by_user and partial message_unsent_by_recipient indexes support this optimized approach, avoiding full table scans and temporary group-by operations.

Test Plan

  1. Verify the UI correctly displays unsent message counts for recipients (see "Walkthrough" video).
  2. Examine recipient-query-plans.log to confirm:
    • No SCAN Message in Query A or B.
    • No USE TEMP B-TREE FOR GROUP BY.
    • Recipient query (Query A) uses an index search.
    • Message count query (Query B) uses message_unsent_by_recipient index.
  3. Review recipient-query-timings.log for performance improvements compared to the legacy query.
  4. Ensure prisma/migrations/20260202160000-recipient-message-indexes/migration.sql is applied, creating the necessary indexes.

Checklist

  • Tests updated (benchmark script)
  • Docs updated

Screenshots


Recipients list shows prepared message counts.

recipients-prepared-messages


Open in Cursor Open in Web


Note

Medium Risk
Touches core recipient list data-loading and introduces new SQL + indexes; risk is mainly incorrect counts or query regressions if the typed SQL/index usage behaves differently across environments.

Overview
Improves recipients list performance by removing Prisma _count aggregation for unsent messages and instead fetching recipients first, then querying unsent message counts for just those recipient IDs via new typed SQL getunsentmessagecounts and merging results into messageCount.

Adds SQLite indexes (recipient_by_user composite and a partial message_unsent_by_recipient on unsent messages) and updates the benchmark script to measure the new split-query approach with configurable recipient page sizing.

Written by Cursor Bugbot for commit f228e88. This will update automatically on new commits. Configure here.

cursoragent and others added 4 commits February 2, 2026 18:35
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 2, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

cursoragent and others added 4 commits February 2, 2026 19:09
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
@kentcdodds kentcdodds marked this pull request as ready for review February 2, 2026 19:42
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is ON. A Cloud Agent has been kicked off to fix the reported issue.

Comment thread app/routes/_app+/recipients+/_layout.tsx Outdated
cursoragent and others added 3 commits February 2, 2026 19:53
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
Co-authored-by: me <me@kentcdodds.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Feb 2, 2026

Bugbot Autofix prepared fixes for 1 of the 1 bugs found in the latest run.

  • ✅ Fixed: Pagination backend without frontend causes data loss
    • Removed the backend pagination limit so all recipients are returned until a proper frontend pagination UI is implemented.

@kentcdodds kentcdodds merged commit 5b1bda8 into main Feb 2, 2026
1 of 5 checks passed
@kentcdodds kentcdodds deleted the cursor/recipient-unsent-messages-800d branch February 2, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants